<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>元素的数据存储(.data/.removeData)</title>
    <script src="../jquery-3.4.1.js"></script>
    <style>
        .left,
        .right {
            width: 300px;
            height: 120px;
        }
        .left div,
        .right div {
            width: 100px;
            height: 90px;
            padding: 5px;
            margin: 5px;
            float: left;
            border: 1px solid #ccc;
        }
        .left div {
            background: #bbffaa;
        }
        .right div {
            background: yellow;
        }
    </style>
</head>
<body>
    <h2>jQuery.data()静态方法</h2>
    <div class="left">
        <div class="aaron">
            <p>点击看结果</p>
            <p>jQuery.data</p>
        </div>
        <div><span></span></div>
    </div>
    <h2>.data()实例方法</h2>
    <div class="right">
        <div class="aaron">
            <p>点击看结果</p>
            <p>.data</p>
        </div>
        <div><span></span></div>
    </div>
</body>

<script>
    $('.left').click(function () {
        //设置数据
        var ele = $(this);
        $.data(ele,"a","data test");
        $.data(ele,"b",{
            name:"SkyEagle"
        });
        //取出数据
        var reset = $.data(ele,"a") + "</br>" +
                $.data(ele,"b").name;
        ele.find("span").append(reset)
    });

    $(".right").click(function () {
        var ele = $(this);
        ele.data("a","data test");
        ele.data("b",{
            name:"77777"
        });
        //取出数据
        var reset = ele.data("a") + "</br>" +
            ele.data("b").name;
        ele.find("span").append(reset)
        //find() 方法获得当前元素集合中每个元素的后代，通过选择器、jQuery 对象或元素来筛选
    })
</script>

</html>